<!--
 * @Author: [kangjie]
 * @Date: 2022-04-06 14:06:13
 * @LastEditors: [kangjie]
 * @LastEditTime: 2022-04-06 14:25:36
 * @Description: 
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="./js/vue-2.6.12.js"></script>
  <script src="./js/vue-router-3.4.3.js"></script>
</head>

<body>
  <div id="app">
    <div>
      <router-link to="/user">用户界面</router-link>
      <router-link to="/manager">管理员界面</router-link>
    </div>
    <div>
      <router-view></router-view>
    </div>
  </div>
  <script>
    // 创建组件
    let myA = {
      template: `
        <div>用户</div>
      `
    };
    let myB = {
      template: `
        <div>
          <div>
            <router-link to="/managerChild1">子组件1</router-link>
            <router-link to="/managerChild2">子组件2</router-link>
          </div>
          <div>
            <router-view></router-view>
          </div>  
        </div>
      `
    };
    let child1 = {
      template: `
        <div>子组件1</div>
      `
    };
    let child2 = {
      template: `
        <div>子组件2</div>
      `
    };
    // 配置路由对象数组
    let routes = [
      {
        path: '/user',
        component: myA
      },
      {
        path: '/manager',
        component: myB,
        // 重定向
        redirect:'/managerChild2',
        // 二级路由
        children: [
          {
            path: '/managerChild1',
            component: child1
          }, {
            path: '/managerChild2',
            component: child2
          }
        ]
      }
    ];
    // 创建路由器实例对象
    let router = new VueRouter({
      routes: routes
    });
    // 注册路由器对象
    new Vue({
      el: "#app",
      router,
      components: {
        'my-a': myA,
        'my-b': myB
      },
      data: {

      },
      methods: {

      }
    })
  </script>
</body>

</html>